package cz.matasek.dbLogger.database;

/**
 * PostgreSQL database.
 *
 * @author Luboš Matásek
 */
public class PostgreSql extends AbstractDatabaseConnection {

    /**
     * Database platform name.
     */
    private static final String DATABASE_PLATFORM_NAME = "PostgreSQL";
    /**
     * Default port for PostgreSQL database.
     */
    private static final int DEFAULT_PORT = 5432;
    /**
     * JDBC driver class name.
     */
    private static final String JDBC_DRIVER_NAME = "org.postgresql.Driver";
    /**
     * On update triggers support.
     */
    private static final boolean SUPPORTS_ON_UPDATE_TRIGGERS = false;

    /**
     * Creates a new PostgreSQL database object with specified parameters.
     *
     * @param username database username
     * @param password database password
     * @param host database host
     * @param databaseName database name
     * @param port database port
     */
    public PostgreSql(String username, String password, String host, String databaseName, String port) {
        super(DatabasePlatform.POSTGRE_SQL, username, password, host, databaseName, port);
    }

    /**
     * Returns default port number for PostgreSQL database.
     *
     * @return default port number
     */
    public static int getDefaultPort() {
        return PostgreSql.DEFAULT_PORT;
    }

    /**
     * Returns PostgreSQL database platform name.
     *
     * @return database platform name
     */
    public static String getDatabasePlatformName() {
        return PostgreSql.DATABASE_PLATFORM_NAME;
    }

    @Override
    public String getJdbcDriverName() {
        return PostgreSql.JDBC_DRIVER_NAME;
    }

    @Override
    public String getJdbcConnectionString() {
        return "jdbc:postgresql://" + host + ":" + port + "/" + databaseName;
    }

    @Override
    protected String getTriggerVariableEscapeChar() {
        return "";
    }

    @Override
    public boolean supportOnUpdateTriggers() {
        return PostgreSql.SUPPORTS_ON_UPDATE_TRIGGERS;
    }
}
